<?php
include $_SERVER['DOCUMENT_ROOT']. '/lib/DanhMuc.php';
$userOb = new DanhMuc();
//Xu ly them xoa
$command = '';
$id = '';
$message = array();
if (isset($_GET['command'])) {
    $command = $_GET['command'];
}
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
if ($command == 'del') {
    if ($userOb->xoaDanhMuc($id)) {
        $message[] = "Xóa thành công";
    } else {
        $message[] = "Xóa thất bại";
    }
}
$dsDanhMuc= $userOb->layDanhSachDanhMuc();
//-------------------
?>
<link href="admin.css" rel="stylesheet">
<div style="margin: 5px;padding: 10px;">
    <h2 style="color: #0000cc" align="center">Danh mục sản phẩm</h2>
    <div class="messages">
        <?php foreach ($message as $mes): ?>
            <p><?php echo $mes; ?></p>
        <?php endforeach; ?>
    </div>
    <div class="command_area">
        <a href="/admin/capnhatdanhmuc.php">Thêm mới</a>
    </div>
    <table style="width: 100%">
        <thead>
            <tr>
                <th scope="col" align="left">STT</th>
                <th scope="col" align="left">Tiêu Đề</th>
                <th scope="col"></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <?php $a = 1; ?>
            <?php foreach ($dsDanhMuc as $danhmuc): ?>
                <tr>
                    <td scope="col"><?php echo $a++ ?></td>
                    <td scope="col"><?php echo $danhmuc['tieude'] ?></td>
                    <td scope="col"><?php echo "<a href='/admin/capnhatdanhmuc.php?id=" . $danhmuc['id'] . "'>Sửa"; ?></td>
                    <td scope="col"><?php echo "<a href='/admin/danhmuc.php?command=del&id=" . $danhmuc['id'] . "'>Xóa"; ?></td>                   
                </tr>
            <?php endforeach; ?>
        </tbody>
        <tfoot>
            <tr>
                <th scope="row" colspan="8"><p style="color: #0099ff">.:Danh Mục Sản Phẩm:.</p></th>
        </tr>
        </tfoot>
    </table>
</div>